package com.yssw.account.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.account.domain.AccountHead;
import com.yssw.account.service.IAccountHeadService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 财务主Controller
 *
 * @author yssw
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/account/accountHead")
public class AccountHeadController extends BaseController {
    @Autowired
    private IAccountHeadService accountHeadService;

    /**
     * 查询财务主列表
     */
    @PreAuthorize("@ss.hasPermi('account:accountHead:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountHead accountHead) {
        startPage();
        List<AccountHead> list = accountHeadService.selectAccountHeadList(accountHead);
        return getDataTable(list);
    }

    /**
     * 导出财务主列表
     */
    @PreAuthorize("@ss.hasPermi('account:accountHead:export')")
    @Log(title = "财务主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountHead accountHead) {
        List<AccountHead> list = accountHeadService.selectAccountHeadList(accountHead);
        ExcelUtil<AccountHead> util = new ExcelUtil<AccountHead>(AccountHead.class);
        util.exportExcel(response, list, "财务主数据");
    }

    /**
     * 获取财务主详细信息
     */
    @PreAuthorize("@ss.hasPermi('account:accountHead:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(accountHeadService.selectAccountHeadById(id));
    }

    /**
     * 新增财务主
     */
    @PreAuthorize("@ss.hasPermi('account:accountHead:add')")
    @Log(title = "财务主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountHead accountHead) {
        return toAjax(accountHeadService.insertAccountHead(accountHead));
    }

    /**
     * 修改财务主
     */
    @PreAuthorize("@ss.hasPermi('account:accountHead:edit')")
    @Log(title = "财务主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountHead accountHead) {
        return toAjax(accountHeadService.updateAccountHead(accountHead));
    }

    /**
     * 删除财务主
     */
    @PreAuthorize("@ss.hasPermi('account:accountHead:remove')")
    @Log(title = "财务主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(accountHeadService.deleteAccountHeadByIds(ids));
    }
}
